1 /*
2 * Title: S/MIME Project
3 * Description: S/MIME email sending capabilities
4 * @Author Vladan Obradovic
5 * @Version 2.0.1
6 */
7
8
9 package org.webdocwf.util.smime.crypto;
10
11
12 import org.webdocwf.util.smime.exception.SMIMEException;
13
14
15 /***
16 * Algorithm class represents check point for input parameters for the symmetric
17 * encryption. Algorithm names and corresponding key length are:<BR>
18 * DES - 56<BR>
19 * DES_EDE3_CBC - 128, 192<BR>
20 * RC2_CBC - 40, 64, 128<BR>
21 */
22 public class Algorithm {
23
24 /***
25 * Symetric key size which will be returned by getKeySize method.
26 */
27 private static int keySizeInBits = 0;
28
29 /***
30 * Algorithm name which will be returned by getAlgorithmName method.
31 */
32 private String algorithmName = null;
33
34 /***
35 * Object construction with the given name of algorithm and key size in bits.
36 * This constructor performs checking of the imported parameters of the
37 * algorithm and defines specific names for later use in Chiper class.
38 * @param algorithm0 name of the one of the following algorithms: "DES",
39 * "DES_EDE3_CBC" and "RC2_CBC".
40 * @param keySize0 key size in bits.
41 * @exception SMIMEException in case of invalid algorithm names, or in case
42 * of wrong key sizes in bits.
43 */
44 public Algorithm(String algorithm0, int keySize0) throws SMIMEException {
45 if (!algorithm0.equalsIgnoreCase("DES") &&
46 !algorithm0.equalsIgnoreCase("RC2_CBC") &&
47 !algorithm0.equals("DES_EDE3_CBC")) {
48 throw new SMIMEException(this, 1013);
49 }
50 if (algorithm0.equalsIgnoreCase("RC2_CBC")) {
51 algorithmName = "RC2";
52 if (keySize0 != 40 && keySize0 != 64 && keySize0 != 128)
53 throw new SMIMEException(this, 1014);
54 keySizeInBits = keySize0;
55 } else if (algorithm0.equalsIgnoreCase("DES_EDE3_CBC")) {
56 algorithmName = "DESede";
57 if (keySize0 != 128 && keySize0 != 192)
58 throw new SMIMEException(this, 1015);
59 keySizeInBits = keySize0;
60 } else {
61 algorithmName = "DES";
62 if (keySize0 != 56)
63 throw new SMIMEException(this, 1016);
64 keySizeInBits = keySize0;
65 }
66 }
67
68 /***
69 * Returns algorithm name used in the symmetric encryption.
70 * @return Name of the chosen algorithm for symmetric encryption.
71 */
72 public String getAlgorithmName() {
73 return algorithmName;
74 }
75
76 /***
77 * Returns key size in bits which is used in the symmetric algorithm.
78 * @return Key size in bits for the algorithm used in the symmetric encryption.
79 */
80 public int getKeySize() {
81 return keySizeInBits;
82 }
83 }
84
This page was automatically generated by Maven